# Contributor: omni <omni+alpine@hack.org>
# Maintainer: messense <messense@icloud.com>
pkgname=maturin
pkgver=0.13.0
pkgrel=0
pkgdesc="Build and publish crates with pyo3, rust-cpython and cffi bindings"
url="https://github.com/PyO3/maturin"
arch="aarch64 armv7 armhf x86 x86_64 ppc64le" # limited by rust
license="Apache-2.0 MIT"
makedepends="cargo dbus-dev openssl-dev"
checkdepends="py3-virtualenv py3-pyo py3-cffi libffi-dev python3-dev"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/PyO3/maturin/archive/v$pkgver.tar.gz"

build() {
	export OPENSSL_NO_VENDOR=1
	case "$CARCH" in
	  ppc64le | s390x) cargo build --release --locked \
		  --no-default-features --features "log,human-panic,password-storage,upload,native-tls" ;;
		*) cargo build --release --locked --features "password-storage" ;;
	esac

	./target/release/maturin completions bash > $pkgname.bash
	./target/release/maturin completions fish > $pkgname.fish
	./target/release/maturin completions zsh > $pkgname.zsh
}

check() {
	export OPENSSL_NO_VENDOR=1
	# enable interpreter "python" hack
	mkdir "$builddir"/pythonbindir
	ln -s /usr/bin/python3 "$builddir"/pythonbindir/python
	export PATH="$PATH:$builddir/pythonbindir"

	case "$CARCH" in
		ppc64le | s390x) cargo test --release --locked \
			--no-default-features --features "log,human-panic,password-storage,upload,native-tls" ;;
		*) cargo test --release --locked --features "password-storage" ;;
	esac
}

package() {
	install -Dm0755 target/release/$pkgname -t "$pkgdir"/usr/bin
	install -Dm0644 license-apache "$pkgdir"/usr/share/licenses/$pkgname/license-apache
	install -Dm0644 license-mit "$pkgdir"/usr/share/licenses/$pkgname/license-mit
	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/completions/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="836c9e7450a7203db59391876ea52a7fe7c64e3803beb49a5152832aaafee6dd7ce7e6d751772c9ccbb075f5cc7b7299719c7ebf63a0d2abd27070b78268efd8  maturin-0.13.0.tar.gz"
